package com.ishansong.ticket.service.impl;

import com.ishansong.ticket.exception.ServiceDaoException;
import com.ishansong.ticket.exception.ServiceException;
import com.ishansong.ticket.model.BindingUser;
import com.ishansong.ticket.service.BindingUserService;
import com.matrixjoy.dal.dao.Dao;
import com.matrixjoy.dal.dao.exception.DaoException;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;


/**
 * Created by saiyin on 15/10/14.
 *
 */
@Component(value = "bindingUserService")
public class BindingUserServiceImpl implements BindingUserService {
    @Autowired
    private Dao dao;
    @Override
    public BindingUser queryBindingUserByLoginName(String loginName) throws ServiceDaoException, ServiceException {
        try {
            @SuppressWarnings("unchecked")
            List<Serializable> ids = dao.getIdList("queryBindingUserByLoginName", new Object[] { loginName});
            if (!CollectionUtils.isEmpty(ids)) {
                List<BindingUser> bindingUsers = dao.getList(BindingUser.class, ids);
                return bindingUsers.get(0);
            } else {
                return new BindingUser();
            }
        } catch (DaoException e) {
            throw new ServiceDaoException(e);
        }
    }

    public Dao getDao() {
        return dao;
    }

    public void setDao(Dao dao) {
        this.dao = dao;
    }
}
